package com.qf.controller;

import com.qf.entity.Brand;
import com.qf.entity.TbCategory;
import com.qf.entity.TbGoods;
import com.qf.service.BrandService;
import com.qf.service.TbCategoryService;
import com.qf.service.TbGoodsService;
import com.qf.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class TbCategoryController {

    @Autowired
    private TbGoodsService goodsService;

    @Autowired
    private TbCategoryService service;

    @Autowired
    private BrandService bService;

    @RequestMapping("index")
    public String all(Model model, @RequestParam(defaultValue = "1") String catID, String branId, @RequestParam(defaultValue = "1") Integer page,
                      @RequestParam(defaultValue = "2") Integer size) {
        model.addAttribute("branId", branId);
        List<TbCategory> all = service.all();
        model.addAttribute("TbCategory", all);
        model.addAttribute("catID", catID);
        model.addAttribute("page", page);
        PageResult<TbGoods> result = goodsService.selectPage(catID, branId, page, size);
        model.addAttribute("result", result);
        List<Brand> brands = bService.selectByCatId(catID);
        model.addAttribute("BrandAll", brands);
        return "index";
    }

}
